<?php
/**
 * run the following sql first in ur db before testing out
 * @author bbqq <toughgamer@gmail.com>
 * @package com.blib.core
 * @copyright bbqq qstufie.com
 */
/*
CREATE DATABASE `test`;
USE `test`;
CREATE TABLE  `test` (
 `test_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
 `name` VARCHAR( 50 ) NULL ,
 `address` VARCHAR( 200 ) NULL
) TYPE = MYISAM ;
GRANT ALL ON `test`.* TO test@localhost IDENTIFIED BY 'testpass';

 */
require_once dirname(__file__) . '/../blib/blib.php';
/**
 * sample dao class
 */
class tDao extends Blib_Data_Dao_Base
{
    /**
     * the constructor
     */
    public function __construct()
    {
        $options = $this->getConfig('db.options');
        $type    = $this->getConfig('db.type');
        parent::__construct($type, $options);

    }// end __construct


    /**
     * add a new entry
     */
    public function addTest($name, $address)
    {
        return $this->insert(array(
            'name' => "it's a $name",
            'address' => $address
        ), 'test');

    }// end addTest


    /**
     * remove by id
     */
    public function removeTest($id)
    {
        return $this->delete('test', '`test_id` = ' . (int) $id);

    }// end removeTest

}// end tDao
?>
<?php
// use a quick config task here...
Blib::env('mytest');
Blib::allowDebug(true);
Blib::setConf('db.options', array(
    'host' => 'localhost',
    'user' => 'test',
    'pass' => 'testpass',
    'dbname' => 'test'
));
Blib::setConf('db.type', 'mysql');
// start with test connection
$tDao = Blib::getSingleton('tDao');
// $tDao->dump();

// test insert
Blib::_bstart('start bench marking dao');
// another test: use passthru
// clear all
// Blib::dump(Blib::clearPdo(), $tDao);
// Blib::clearSingleton();
// $tDao = Blib::getSingleton('tDao');

// bench it
$result = Blib::_bench('addTest', $tDao, 'test one more time', 'hey test!');
Blib::dump($result);

$result = Blib::_bench('removeTest', $tDao, 1);
Blib::dump($result);

// result:
Blib::_bstatus();
?>